﻿


function grid_processstep_add() {
    //location.href =decodeURIComponent("/User/UserAdd") ;
    grid_processstep_show();
}

function save_processstep() {
    //addDialog.frame.save();
    var form = $('#frmProcessStep');
    form.submit();
}

function grid_processstep_edit() {
    if (processstepgrid.getSelecteds().length == 0) {
        $.ligerDialog.warn('至少选择一个逻辑条件进行修改！', '温馨提示');
        return;
    }
    var processstep = processstepgrid.getSelected();
    grid_processstep_show(processstep.StepName, processstep.CurrentProcessID, processstep.NextProcessID, processstep.ID);
}

function grid_processstep_show(processstepname, currentProcessID, nextProcessID, processstepId) {
    var title = "添加逻辑条件";

    if (processstepname != null) {
        title = "修改逻辑条件【 " + processstepname + " 】"
        processstep_set(processstepname, currentProcessID, nextProcessID, processstepId);
    } else {
        processstep_reset();
    }
    saveDialog = $.ligerDialog.open({
        title: title,
        id: 'processstepDialog',
        name: 'processstepDialog',
        slide: false,
        isHidden: false,
        modal: true,
        target: $("#frmProcessStep"),
        //        url: "/processstep/UserAdd",
        width: 400, isResize: true, allowClose: false,
        buttons: [
                    { text: '保存', onclick: save_processstep },
                    {
                        text: '取消', onclick: function (item, dialog) {
                            dialog.hide();
                            processstep_reset();
                        }
                    }
                ]
    });
}
function processstep_set(processstepname, currentProcessID, nextProcessID, processstepId) {
    //$("#txtUserName").ligerTextBox('option', 'disabled', false);
    //  selType.setValue(type);
    $("#txtProcessStepName").val(processstepname);
    liger.get("currentProcess").setValue(currentProcessID);
    liger.get("nextProcess").setValue(nextProcessID);
    $("#processStepID").val(processstepId);
    $("#lblmsg").val("");
}


function processstep_reset() {
    $(".l-text-field").ligerHideTip();
    $("#txtProcessStepName").val("");
    liger.get("currentProcess").setValue("");
    liger.get("nextProcess").setValue("");
    $("#processStepID").val("0");
    $("#lblmsg").val("");
}

function grid_processstep_delete() {
    var processstepIDs = "";
    var names = "";

    if (processstepgrid.getSelecteds().length == 0) {
        $.ligerDialog.warn('至少选择一个逻辑条件进行删除！', '温馨提示');
        return;
    }
    var selected = processstepgrid.getSelecteds();
    if (selected.length == 0) {
        $.ligerDialog.warn('请选择要删除的数据！', '温馨提示');
        return;
    }

    for (var i = 0; i < selected.length; i++) {
        processstepIDs += selected[i].ID + ",";
        names += selected[i].StepName + ",";
    }
    names = names.substring(0, names.length - 1);
    processstepIDs = processstepIDs.substring(0, processstepIDs.length - 1);
    processstep_delete(processstepIDs, names);

}

function processstep_delete(processstepIDs, realName) {
    $.ligerDialog.confirm('删除后流程将会不完整，确定删除逻辑条件[' + realName + ']吗？', '温馨提示', function (result) {
        if (result) {
            $.ajax({
                url: '/processstep/processstepDelete',
                data: "processstepIDs=" + processstepIDs,
                type: "post",
                success: function (result) {
                    if (result == "1") {
                        //employee.deleteSelectedRow();
                        $.ligerDialog.success("成功删除逻辑条件[" + realName + "]。");
                        grid_processstep_refresh();
                    } else {
                        $.ligerDialog.error('删除失败！', '温馨提示');
                    }
                }
            });
        }
    });
}
function changestate(id, state, realName) {
    var statestr = "禁用";
    if (state == 1) {
        statestr = "启用";
    }
    $.ligerDialog.confirm('确定【' + statestr + '】逻辑条件[' + realName + ']吗？', '温馨提示', function (result) {
        if (result) {
            $.ajax({
                url: '/processstep/processstepChangeStatus',
                data: "processstepID=" + id + "&status=" + state,
                type: "post",
                success: function (result) {
                    if (result == "1") {
                        //employee.deleteSelectedRow();
                        $.ligerDialog.success(statestr + "节点成功");
                        grid_processstep_refresh();
                    } else {
                        $.ligerDialog.error(statestr + "节点失败！", '温馨提示');
                    }
                }
            });
        }
    });
}
function grid_processstep_refresh() {
    processstepgrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
    processstepgrid.loadData();
}
function grid_processstep_back() {
    location.href = decodeURIComponent("/Process/Index");
}
 